package com.jspgou.cms.action.member;

import static com.jspgou.cms.Constants.MEMBER_SYS;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.jspgou.cms.entity.Order;
import com.jspgou.cms.entity.Report;
import com.jspgou.cms.entity.ReportType;
import com.jspgou.cms.entity.ShopMember;
import com.jspgou.cms.manager.OrderMng;
import com.jspgou.cms.manager.ReportMng;
import com.jspgou.cms.manager.ReportTypeMng;
import com.jspgou.cms.web.CmsUtils;
import com.jspgou.cms.web.ShopFrontHelper;
import com.jspgou.cms.web.SiteUtils;
import com.jspgou.common.web.springmvc.MessageResolver;
import com.jspgou.core.entity.Website;

@Controller
public class ReportFroAct {
     private static final Logger log=LoggerFactory.getLogger(ReportFroAct.class);
     
 	/**
 	 * 会员投诉举报页
 	 */
 	private static final String TPL_REPORT_APPLY="tpl.reportApply";
 	/**
 	 * 会员投诉举报列表页
 	 */
 	private static final String TPL_REPORT_LIST="tpl.reportList";
 	/**
 	 * 会员投诉举报查看页
 	 */
 	private static final String TPL_REPORT_VIEW="tpl.reportView";
 	/**
 	 * 会员投诉举报修改页
 	 */
 	private static final String TPL_REPORT_EDIT="tpl.reportEdit";
 	
    @RequestMapping(value="/reportFro/report_list.jspx")
    public String refundList(String cl,Integer pageNo,HttpServletRequest request,
   		 HttpServletResponse response,ModelMap model){
   	 Website web=SiteUtils.getWeb(request);
   	 ShopMember member=CmsUtils.getMember(request);
   	 //用户没有登录，跳转到登录页
   	 if(member==null||member.getIsEmployee()){
   		 return ShopFrontHelper.showLogin(request, model, web);
   	 }
   	 model.addAttribute("cl", cl);
   	 model.addAttribute("member", member);
   	 ShopFrontHelper.setCommonData(request, model, web);
   	 ShopFrontHelper.frontPageData(request, model);
   	 return web.getTplSys(MEMBER_SYS, MessageResolver.getMessage(request,TPL_REPORT_LIST), request);
    }
    
    @RequestMapping(value="/reportFro/report_view.jspx")
    public String refundView(Long id,HttpServletRequest request,
   		 HttpServletResponse response,ModelMap model){
   	 Website web=SiteUtils.getWeb(request);
   	 ShopMember member=CmsUtils.getMember(request);
   	 //用户没有登录，跳转到登录页
   	 if(member==null||member.getIsEmployee()){
   		 return ShopFrontHelper.showLogin(request, model, web);
   	 }
   	 Report bean=manager.findById(id);
   	 model.addAttribute("report", bean);
   	 model.addAttribute("member", member);
   	 model.addAttribute("order", bean.getOrder());
   	 ShopFrontHelper.setCommonData(request, model, web);
   	 ShopFrontHelper.frontPageData(request, model);
   	 return web.getTplSys(MEMBER_SYS, MessageResolver.getMessage(request,TPL_REPORT_VIEW), request);
    }
 	
     @RequestMapping(value="/reportFro/report_apply.jspx")
     public String refundApply(Long orderId,HttpServletRequest request,
    		 HttpServletResponse response,ModelMap model){
    	 Website web=SiteUtils.getWeb(request);
    	 ShopMember member=CmsUtils.getMember(request);
    	 //用户没有登录，跳转到登录页
    	 if(member==null||member.getIsEmployee()){
    		 return ShopFrontHelper.showLogin(request, model, web);
    	 }
    	 Order order =orderMng.findById(orderId);
    	 List<ReportType> typelist=reportTypeMng.getListByDisable(false);
    	 model.addAttribute("order", order);
    	 model.addAttribute("typelist", typelist);
    	 ShopFrontHelper.setCommonData(request, model, web);
    	 ShopFrontHelper.frontPageData(request, model);
    	 return web.getTplSys(MEMBER_SYS, MessageResolver.getMessage(request,TPL_REPORT_APPLY), request);
     }
     
     @RequestMapping(value="/reportFro/apply_save.jspx")
     public String applySave(Report bean,Long orderId,Long typeId,HttpServletRequest request,
    		 HttpServletResponse response,ModelMap model){
    	 Website web=SiteUtils.getWeb(request);
    	 ShopMember member=CmsUtils.getMember(request);
    	 //用户没有登录，跳转到登陆页
    	 if(member==null||member.getIsEmployee()){
    		 return ShopFrontHelper.showLogin(request, model, web);
    	 }
    	 manager.save(bean,web,orderId,member.getId(),typeId);
    	 return "redirect:report_list.jspx";
     }
     
     @RequestMapping(value="/reportFro/report_edit.jspx")
     public String refundEdit(Long id,HttpServletRequest request,
    		 HttpServletResponse response,ModelMap model){
    	 Website web=SiteUtils.getWeb(request);
    	 ShopMember member=CmsUtils.getMember(request);
    	 //用户没有登录，跳转到登录页
    	 if(member==null||member.getIsEmployee()){
    		 return ShopFrontHelper.showLogin(request, model, web);
    	 }
    	 Report bean=manager.findById(id);
    	 List<ReportType> typelist=reportTypeMng.getListByDisable(false);
    	 model.addAttribute("report", bean);
    	 model.addAttribute("order", bean.getOrder());
    	 model.addAttribute("typelist", typelist);
    	 ShopFrontHelper.setCommonData(request, model, web);
    	 ShopFrontHelper.frontPageData(request, model);
    	 return web.getTplSys(MEMBER_SYS, MessageResolver.getMessage(request,TPL_REPORT_EDIT), request);
     }
     
     @RequestMapping(value="/reportFro/apply_update.jspx")
     public String applySave(Report bean,HttpServletRequest request,
    		 HttpServletResponse response,ModelMap model){
    	 Website web=SiteUtils.getWeb(request);
    	 ShopMember member=CmsUtils.getMember(request);
    	 //用户没有登录，跳转到登陆页
    	 if(member==null||member.getIsEmployee()){
    		 return ShopFrontHelper.showLogin(request, model, web);
    	 }
    	 manager.update(bean);
    	 return "redirect:report_list.jspx";
     }
     
     @Autowired
     private ReportMng manager;
     @Autowired
     private ReportTypeMng reportTypeMng;
     @Autowired
     private OrderMng orderMng;
	
	
}
